package com.marktotop.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.marktotop.entity.Employee;
import com.marktotop.entity.Salary;
import com.marktotop.response.ResultBean;
import com.marktotop.response.ResultCode;
import com.marktotop.service.IEmployeeService;
import com.marktotop.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * SalarySobCfgController - 员工账套
 *
 * @author WXLD
 * @Data 2021/7/1
 * @Since 1.0
 */
@RestController
@RequestMapping("/salary/sobcfg")
@Api(tags = "员工账套接口")
public class SalarySobCfgController {

    @Autowired
    private ISalaryService salaryService;

    @Autowired
    private IEmployeeService employeeService;

    /**
     * 获取所有工资账套
     * @return
     */
    @ApiOperation(value = "获取所有工资账套")
    @RequestMapping(value = "/salaries",method = RequestMethod.GET)
    public ResultBean getAllSalaries(){
        List<Salary> listSalary = salaryService.list();
        if (null == listSalary){
            return ResultBean.result(ResultCode.NON_RESULT);
        }
        return ResultBean.ok().data("AllSalaries",listSalary);
    }


    /**
     * 获取所有员工工资账套
     *
     * @param currentPage
     * @param size
     * @return
     */
    @ApiOperation(value = "获取所有员工账套")
    @RequestMapping(value = "/",method = RequestMethod.GET)
    public ResultBean getEmployeeSalary(@RequestParam(defaultValue = "1") Integer currentPage,
                                        @RequestParam(defaultValue = "10")Integer size){

        return employeeService.getEmployeeSalary(currentPage,size);
    }


    /**
     * 更新员工工资账套
     *
     * @param eid
     * @param sid
     * @return
     */
    @ApiOperation(value = "更新员工账套")
    @RequestMapping(value = "/",method = RequestMethod.PUT)
    public ResultBean updateEmployeeSalary(Integer eid,Integer sid){
        if (employeeService.update(new UpdateWrapper<Employee>().set("salaryId",sid).eq("id",eid))){
            return ResultBean.ok().message("更新员工账套信息成功!");
        }
        return ResultBean.error().message("员工账套信息更新失败!");
    }
}
